cmake_minimum_required(VERSION 3.10)
project(dexterous_hand_control)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 设置静态链接
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc -static-libstdc++ -static")

# 编译serial库
add_subdirectory(serial)

# 创建协议库
add_library(dexterous_hand_protocol STATIC
    protocol.cpp
    packet.cpp
    dexterous_hand.cpp
)

# 设置协议库的头文件路径
target_include_directories(dexterous_hand_protocol PUBLIC
    ${CMAKE_CURRENT_SOURCE_DIR}
    ${CMAKE_SOURCE_DIR}/serial/include
)

# 协议库链接serial库
target_link_libraries(dexterous_hand_protocol PUBLIC
    serial
)

# 创建主程序可执行文件
add_executable(dexterous_hand_control
    main.cpp
)

# 设置主程序的头文件路径
target_include_directories(dexterous_hand_control PRIVATE
    ${CMAKE_CURRENT_SOURCE_DIR}
    ${CMAKE_SOURCE_DIR}/serial/include
)

# 主程序链接库
target_link_libraries(dexterous_hand_control PRIVATE
    dexterous_hand_protocol
    serial
    ws2_32  # Windows下需要的socket库
)

# 创建WebSocket服务器可执行文件
add_executable(ws_server ws_server.cpp)

# 设置WebSocket服务器的头文件路径
# vcpkg集成crow时，头文件路径自动可用，无需手动添加
find_package(Crow CONFIG REQUIRED)
find_package(nlohmann_json CONFIG REQUIRED)

# WebSocket服务器链接库
# crow为header-only，无需链接库，但需链接dexterous_hand_protocol和serial
# 以及ws2_32（Windows下socket库）
target_link_libraries(ws_server PRIVATE
    dexterous_hand_protocol
    serial
    ws2_32
    mswsock
    Crow::Crow
    nlohmann_json::nlohmann_json
)